fix: handle search errors and stale reconnect sessions#1096
Open
octo-patch wants to merge 1 commit intoItzCrazyKns:masterfrom
Open
fix: handle search errors and stale reconnect sessions#1096octo-patch wants to merge 1 commit intoItzCrazyKns:masterfrom
octo-patch wants to merge 1 commit intoItzCrazyKns:masterfrom
Conversation
…yKns#1006) - Wrap SearchAgent.searchAsync in try/catch: on failure, emit an error event to the session and update the message status to 'error' in the database. Previously, any exception left the message stuck in 'answering' state forever. - In useChat.tsx checkReconnect: check res.ok before reading the stream. When the backend session no longer exists (e.g. after a server restart), the reconnect API returns 404. The frontend now marks the message as 'error' and exits loading state instead of hanging indefinitely.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1006
Problem
When a network failure or any unhandled exception occurs during
SearchAgent.searchAsync, the error is silently swallowed (the method is called withoutawaitin the route handler). This leaves the message instatus: 'answering'in the database indefinitely. On reconnect, the frontend calls/api/reconnect/:backendIdwhich returns 404 because the session is gone (especially after a server/container restart). Since the frontend didn't checkres.ok, it tried to read the 404 response body as an SSE stream — nothing matched a known message type, so loading stayedtrueand the stuck "Brainstorming" state persisted, making all follow-up questions impossible.Solution
Backend (
src/lib/agents/search/index.ts)searchAsyncbody in atry/catcherrorevent to the session (so any active listener gets notified) and update the message status to'error'in the databaseFrontend (
src/lib/hooks/useChat.tsx)/api/reconnect/:id, checkres.okbefore attempting to read the streamloading: false, clear the reconnect flag, and mark the message as'error'so the user can retryTesting
Summary by cubic
Prevent chats from getting stuck in “Brainstorming” by handling search errors and stale reconnect sessions (fixes #1006). On failure, messages now enter an “error” state and the UI stops loading so users can retry.
searchAsyncin try/catch; on error, emiterrorto the session and set the message status toerrorin the DB./api/reconnect/:id, checkres.ok; on non-OK (e.g., 404), stop loading, clear reconnect, and mark the last message aserror.Written for commit b5e1d9f. Summary will update on new commits.